﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TV_Agenda_V2.Objects
{
    public class Episode
    {
        public Int32 EpisodeNumber { get; set; }
        public Int32 SeasonEpisodeNumber { get; set; }
        public Int32 SeasonNumber { get; set; }
        public String ProdNumber { get; set; }
        public String AirDate { get; set; }
        public String Link { get; set; }
        public String Title { get; set; }
        public Boolean DisplayBold { get; set; }

        private DateTime airDate;

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override String ToString()
        {
            return ToString(MainWindow.Settings.EpisodeFormat, MainWindow.Settings.DateFormat);
        }

        /// <summary>
        /// Gets the string representation of the show.<br/>
        /// %en = EpisodeNumber<br/>
        /// %enZ = EpisodeNumber but with leading 0. Example: 01, 02, 10<br/>
        /// %se = SeasonEpisodeNumber<br/>
        /// %seZ = SeasonEpisodeNumber but with leading 0<br/>
        /// %sn = SeasonNumber<br/>
        /// #snZ = SeasonEpisodeNumber but with leading 0<br/>
        /// %pn = ProdNumber<br/>
        /// %ad = Airdate<br/>
        /// %ln = Link<br/>
        /// %t = Title
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="Dateformat">The dateformat.</param>
        /// <returns></returns>
        public String ToString(String format, String dateFormat)
        {
            format = format.Replace("%enZ", EpisodeNumber.ToString("00"));
            format = format.Replace("%en", EpisodeNumber.ToString());
            format = format.Replace("%seZ", SeasonEpisodeNumber.ToString("00"));
            format = format.Replace("%se", SeasonEpisodeNumber.ToString());
            format = format.Replace("%snZ", SeasonNumber.ToString("00"));
            format = format.Replace("%sn", SeasonNumber.ToString());
            format = format.Replace("%pn", ProdNumber);
            format = format.Replace("%ad", DateTime.TryParse(AirDate,out airDate) ? airDate.ToString(dateFormat) : AirDate);
            format = format.Replace("%ln", Link);
            format = format.Replace("%t", Title);
            return format;
        }
    }
}
